import 'package:flutter/services.dart';

import 'hvn_global.dart';

class HVNChannelManager {
  static const MethodChannel toolChannel = MethodChannel('hvn.ovpn.connect');

  static const String prepareVpn = "vpnPrepare";
  static const String connectVpn = "connectVpn";
  static const String disConnectVpn = "disConnectVpn";

  static const String vpnStatus = "vpnStatus";

  static const String openUrl = "openUrl";
  static const String fbDeepUrl = "fbDeepUrl";

  static const String reqTrackingAuth = "requestTrackingAuthorization";

  static HVNChannelManager share = HVNChannelManager();

  Future<bool> ovpnPrepare() async {
    var isSuc = await toolChannel.invokeMethod(prepareVpn);
    return isSuc;
  }

  /// 调用链接VPN
  Future<bool> ovpnConnect(String path) async {
    bool isSuc = await toolChannel.invokeMethod(connectVpn, path);
    return isSuc;
  }

  /// 调用断开VPN
  Future<bool> ovpnDisconnect() async {
    bool isSuc = await toolChannel.invokeMethod(disConnectVpn);
    return isSuc;
  }

  /// 获取应用启动的目标链接
  Future<String> appOpenUrl() async {
    String url = await toolChannel.invokeMethod(openUrl);
    if (isTestJumpShare) {
      return "jump:aaaa";
    }
    return url;
  }

  /// 获取Facebook应用启动的目标链接
  Future<String> appFbDeepUrl() async {
    String url = await toolChannel.invokeMethod(fbDeepUrl);
    if (isTestJumpShare) {
      return "jump:bbbb";
    }
    return url;
  }

  Future<bool> requestTrackingAuthorization() async {
    return await toolChannel.invokeMethod(reqTrackingAuth);
  }
}
